/**
 *	The NeuroCoSA Toolkit
 *	Copyright (C) 2003-6 Stuart Meikle.
 *
 *	This is free software; you can redistribute it and/or
 *	modify it under the terms of the GNU Lesser General Public
 *	License as published by the Free Software Foundation; either
 *	version 2.1 of the License, or (at your option) any later version.
 *
 *	This library is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *	Lesser General Public License for more details.
 *
 * @author	Stuart Meikle
 * @version	2006-halloween(mk2)
 * @license	LGPL
 */

package org.stumeikle.NeuroCoSA;

// demo user classes
import java.util.*;
import java.lang.*;
import org.stumeikle.NeuroCoSA.Brain;
import org.stumeikle.NeuroCoSA.DPU;
import org.stumeikle.NeuroCoSA.DataBlock;
import org.stumeikle.NeuroCoSA.Cortex;
import org.stumeikle.NeuroCoSA.Layer;
import org.stumeikle.NeuroCoSA.NIS.*;
import org.stumeikle.NeuroCoSA.CortexInfoService;
import org.stumeikle.NeuroCoSA.Neuron;
import org.stumeikle.NeuroCoSA.SimpleNeuron;
import org.stumeikle.NeuroCoSA.Vesicle;
import org.stumeikle.NeuroCoSA.AutoCluster.NMeasurable;
import org.stumeikle.NeuroCoSA.AutoCluster.NScalar;

public class SimpleDebugNeuron extends SimpleNeuron
{
    Vesicle	iLearn;
    String	iDbg;
    NMeasurable	iExemplar;
    Info	iIncomingSignal;
    static final double	iNeuronSeparationThreshold=0.7;//used by layer
    double	iNeuronNoiseThreshold;
    double	iDistanceMod;


    public SimpleDebugNeuron(Layer l)
    {
	super(l);
	
	iLearn = new Vesicle(Vesicle.LEARN_VESICLE);
	iLearn.setSignalStrength(0.0);
	iDbg = new String("simpledebug");
	iIncomingSignal = (Info)getLayer().getInfoService().findInfo("IncomingSignal");
	iNeuronNoiseThreshold = 0.1;
	iDistanceMod = 1.5;
    }
    
    public	void		setExemplar(NMeasurable n)
    {
	//read in data from the LIS and set our template
	try{
		NScalar s = (NScalar)n;
		iDbg = new String( "Debug:" + s.getValue() );
	} catch(Exception e ) {}

	iExemplar= n;
    }



    public void			startOfVesicleProcessing()
    {
	//read the input signal and create a vesicle
	NMeasurable	nm = (NMeasurable) iIncomingSignal.getValue();
	double		value;
	
	//try to extract a measurable from this
	iLearn.setSignalStrength(0.0);

	try
	{	    
	    //calculate the distance from the nmeasurable to our exemplar and
	    //set the firing strength of the learn vesicle accordingly
	    double d = nm.distanceTo( iExemplar );
	    value = 1.0 - (d*iDistanceMod);
	    
	    if (value<0.1)	value = 0.0;
	    iLearn.setSignalStrength( value );

	} catch(Exception e) {}

	processVesicle( iLearn, null );
    }


    public	String		getDEBUGLabel()	
    {
	//should be overloaded by the user
	return iDbg;
    }
}

